<?php
	$id=!empty($_GET["id"])?$_GET["id"]*1:NULL;
    $catid=!empty($_GET["cat_id"])?$_GET["cat_id"]*1:0;
	$key=!empty($_GET["key"])?trim($_GET["key"]):NULL;
	$firstRow=!empty($_GET["firstRow"])?$_GET["firstRow"]:NULL;
	$totalRows=!empty($_GET["totalRows"])?$_GET["totalRows"]:NULL;
	$orderby=!empty($_GET["orderby"])?$_GET['orderby']*1:NULL;
    $where = " 1 ";
	//===================================分类
	$cat_sql = "select * from ".NEWSCAT." where ishome = 1 and pid = 0 and catid != 6 ";
	$db->query($cat_sql);
	$cat_list = $db->getRows();
    $catname=array_column($cat_list,'cat','catid');
	if(!empty($catid)){
		$where .= " and n.classid = '{$catid}' ";
	}

	$article =  "select * from ".NEWSCAT." where ishome = 1 and pid = 6 ";
	$db->query($article);
	$article_list = $db->getRows();
	$article_ids = array_column($article_list,'catid');
    $where_article= implode(',',$article_ids);
	$where_article = !empty($where_article) ? $where_article : 0;
    if(!empty($where_article)){
		$where .= " and n.classid not in ($where_article) ";
	}
	$order = " order by n.nid desc";

	//--------------------------------------------------

	include_once("includes/page_utf_class.php");
	$page = new Page;
	$page->url=$config['weburl'].'/';
	$page->listRows= 10;
	
	$sql = "select n.*,d.con from ".NEWSD." n left join ".NEWSDATA." d on n.nid = d.nid where $where ".$order;
		
	if(!$page->__get('totalRows'))
	{
		$db->query($sql);
		$page->totalRows =$db->num_rows();
	}
	$sql.=" limit ".$page->firstRow.", ".$page->listRows;
	//--------------------------------------------------
	$db->query($sql);
	$prol=$db->getRows();
	$prolist['list']=$prol;
	$prolist['page']=$page->get_pc_prompt();
	$prolist['count']=$page->totalRows;
	$tpl->assign("prolist",$prolist);
	//------------------------------------------------------
$nsql = "select * from ".NEWSD." where 1 and classid not in ($where_article) order by nid desc limit 0,5";
$db->query($nsql);
$new_list = $db->getRows();
$tpl->assign('new_list',$new_list);
	
	//----------------------------SEO
	$config['title']=str_replace('[catname]',$cat['cat'],$config['title2']);
	$config['keyword']=str_replace('[catname]',$cat['cat'],$config['keyword2']);
	$config['description']=str_replace('[catname]',$cat['cat'],$config['description2']);
	
	//=====================================================

	$tpl->assign("catid",$catid);
	$tpl->assign("cat_list",$cat_list);
    $tpl->assign("catname",$catname[$catid]);
	include_once("footer.php");
	$out=tplfetch("news_list.htm");

?>